﻿<UserControl x:Class="Test.Silverlight.DataGrid.ColumnsLayout"
    xmlns="http://schemas.microsoft.com/client/2007" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:grid="clr-namespace:DevExpress.AgDataGrid;assembly=DevExpress.AgDataGrid.v8.2"
    xmlns:local="clr-namespace:Test.Silverlight.DataGrid;assembly=Test.Silverlight.DataGrid"
    xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows">
    
    <UserControl.Resources>
        <Style x:Name="ColumnHeaderStyle" TargetType="grid:AgDataGridColumnHeader">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="grid:AgDataGridColumnHeader">
                        <Grid x:Name="RootElement" Cursor="Hand">
                            <Grid.Background>
                                <LinearGradientBrush EndPoint="0.5,0" StartPoint="0.5,1">
                                    <GradientStop Color="#FF6CA2DF"/>
                                    <GradientStop Color="#FF92BAE7" Offset="1"/>
                                </LinearGradientBrush>
                            </Grid.Background>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="*" />
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>
                            <vsm:VisualStateManager.VisualStateGroups>
                                <vsm:VisualStateGroup x:Name="CommonStates">
                                    <vsm:VisualState x:Name="Normal">
                                        <Storyboard FillBehavior="HoldEnd">
                                            <DoubleAnimation Duration="00:00:00.5" Storyboard.TargetName="MouseOverElement" Storyboard.TargetProperty="Opacity" To="0" />
                                            <DoubleAnimation Duration="00:00:00.001" Storyboard.TargetName="PressedElement" Storyboard.TargetProperty="Opacity" To="0" />
                                        </Storyboard>
                                    </vsm:VisualState>
                                    <vsm:VisualState x:Name="MouseOver">
                                        <Storyboard FillBehavior="HoldEnd">
                                            <DoubleAnimation Duration="00:00:00.25" Storyboard.TargetName="MouseOverElement" Storyboard.TargetProperty="Opacity" To="1" />
                                            <DoubleAnimation Duration="00:00:00.001" Storyboard.TargetName="PressedElement" Storyboard.TargetProperty="Opacity" To="0" />
                                        </Storyboard>
                                    </vsm:VisualState>
                                    <vsm:VisualState x:Name="Pressed">
                                        <Storyboard FillBehavior="HoldEnd">
                                            <DoubleAnimation Duration="00:00:00.001" Storyboard.TargetName="MouseOverElement" Storyboard.TargetProperty="Opacity" To="0" />
                                            <DoubleAnimation Duration="00:00:00.001" Storyboard.TargetName="PressedElement" Storyboard.TargetProperty="Opacity" To="1" />
                                        </Storyboard>
                                    </vsm:VisualState>
                                </vsm:VisualStateGroup>
                            </vsm:VisualStateManager.VisualStateGroups>
                            <Border x:Name="MouseOverElement" Grid.ColumnSpan="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Opacity="0">
                                <Border.Background>
                                    <LinearGradientBrush EndPoint="0.5,0" StartPoint="0.5,1">
                                        <GradientStop Color="#508acc" Offset="0"/>
                                        <GradientStop Color="#6ca0d9" Offset="1"/>
                                    </LinearGradientBrush>
                                </Border.Background>
                            </Border>
                            <Border x:Name="PressedElement" Grid.ColumnSpan="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" 
								Opacity="0" Background="#FF585858" />
                            <Rectangle x:Name="Dragger" Opacity="0" Stretch="Fill" Fill="AliceBlue" Grid.Column="0" StrokeThickness="1"/>
                            <StackPanel Orientation="Vertical">
                                <ContentControl Grid.ColumnSpan="3" Content="{TemplateBinding Content}" Grid.Column="0" Margin="6,6,0,6" VerticalAlignment="Center"
                                                  Foreground="White" IsHitTestVisible="False"/>
                                <StackPanel Orientation="Horizontal">
                                    <local:AgToggleButton Margin="1" Content="F" FontSize="11" IsChecked="False" Click="cbFixedWidth_Click" Width="17" Height="18">
                                        <ToolTipService.ToolTip><TextBlock Text="Fixed Width"/></ToolTipService.ToolTip>
                                    </local:AgToggleButton>
                                    <local:AgToggleButton Margin="1" Content="S" FontSize="11" IsChecked="True"  Click="cbAllowResize_Click" Width="17" Height="18">
                                        <ToolTipService.ToolTip><TextBlock Text="Allow Sizing"/></ToolTipService.ToolTip>
                                    </local:AgToggleButton>
                                    <local:AgToggleButton Margin="1" Content="W" FontSize="11" IsChecked="False" Click="cbWordWrap_Click" Loaded="cbWordWrap_Loaded" Width="17" Height="18">
                                        <ToolTipService.ToolTip><TextBlock Text="Text Wrapping"/></ToolTipService.ToolTip>
                                    </local:AgToggleButton>
                                </StackPanel>
                            </StackPanel>
                            <Rectangle x:Name="Resizer" Opacity="0" Fill="AliceBlue" Width="5" Grid.Column="1" StrokeThickness="1" 
								   Cursor="SizeWE" HorizontalAlignment="Right" VerticalAlignment="Stretch" />
                            <Path x:Name="SortDescendent" Grid.Column="1" Stretch="Fill" Fill="White" Data="F1 M 678,521L 681,527L 682,527L 685,521L 678,521 Z " Height="6"
                                  HorizontalAlignment="Right" Margin="0,0,8,1" VerticalAlignment="Center" Width="7" Visibility="{TemplateBinding SortDescendentVisibility}"
                                  Cursor="Hand"/>
                            <Path x:Name="SortAscendent" Grid.Column="1" Stretch="Fill" Fill="White" Data="F1 M 685,527L 682,521L 681,521L 678,527L 685,527 Z " Height="6"
                                  HorizontalAlignment="Right" Margin="0,0,8,1" VerticalAlignment="Center" Width="7" Visibility="{TemplateBinding SortAscendentVisibility}"
                                  Cursor="Hand"/>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <DataTemplate x:Name="OptionsPanelTemplate">
            <Grid x:Name="OptionsPanel" Loaded="OptionsPanel_Loaded">
                <CheckBox x:Name="cbColumnAutoWidth"
                  Checked="cbColumnAutoWidth_IsCheckedChanged"
                  Content="Column auto width"
                  Unchecked="cbColumnAutoWidth_IsCheckedChanged"/>
            </Grid>
        </DataTemplate>
    </UserControl.Resources>
    
    <Grid x:Name="LayoutRoot">
        <grid:AgDataGrid x:Name="grid" ShowGroupPanel="Visible">
            <grid:AgDataGrid.Columns>
                <grid:AgDataGridTextColumn FieldName="EmployeeID" MinColumnWidth="77" HeaderStyle="{StaticResource ColumnHeaderStyle}"/>
                <grid:AgDataGridTextColumn FieldName="LastName" MinColumnWidth="77" HeaderStyle="{StaticResource ColumnHeaderStyle}"/>
                <grid:AgDataGridTextColumn FieldName="FirstName" MinColumnWidth="77" HeaderStyle="{StaticResource ColumnHeaderStyle}"/>
                <grid:AgDataGridTextColumn FieldName="Title" MinColumnWidth="77" HeaderStyle="{StaticResource ColumnHeaderStyle}"/>
                <grid:AgDataGridTextColumn FieldName="City" MinColumnWidth="77" HeaderStyle="{StaticResource ColumnHeaderStyle}"/>
                <grid:AgDataGridDateColumn FieldName="BirthDate" MinColumnWidth="60" HeaderStyle="{StaticResource ColumnHeaderStyle}"/>
                <grid:AgDataGridTextColumn FieldName="HomePhone" MinColumnWidth="77" HeaderStyle="{StaticResource ColumnHeaderStyle}"/>
            </grid:AgDataGrid.Columns>
        </grid:AgDataGrid>
    </Grid>
    
</UserControl>
